home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Dialogs / AboutBox.cpp next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  4.8 KB  |  219 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        AboutBox.cpp
  3.  
  4.     Contains:    Functions to handle the About Box display
  5.  
  6.     Owned by:    Chris Linn
  7.  
  8.     Copyright:    © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <1>     10/4/96    CSL        first checked in
  13. */
  14.  
  15. #ifndef __QUICKDRAW__
  16. #include <Quickdraw.h>
  17. #endif
  18.  
  19. #ifndef __DIALOGS__
  20. #include <Dialogs.h>
  21. #endif
  22.  
  23. #ifndef SOM_ODWindowState_xh
  24. #include "WinStat.xh"
  25. #endif
  26.  
  27. #ifndef _USERSRCM_
  28. #include "UseRsrcM.h"
  29. #endif
  30.  
  31. #ifndef _DLGDEFS_
  32. #include "DdgDefs.h"
  33. #endif
  34.  
  35. #ifndef _ODVERSNM_
  36. #include "ODVersnM.h"
  37. #endif
  38.  
  39. #ifndef _PASCLSTR_
  40. #include "PasclStr.h"
  41. #endif
  42.  
  43. #include <stdio.h>
  44.  
  45. //
  46. // Types
  47. //
  48.  
  49. #if PRAGMA_ALIGN_SUPPORTED
  50. #pragma options align=mac68k
  51. #endif
  52.  
  53. struct VersRsrc {
  54.     unsigned long    versionCode;
  55.     short            region;
  56.     Str255            versionStr;
  57. };
  58.  
  59. #if PRAGMA_ALIGN_SUPPORTED
  60. #pragma options align=reset
  61. #endif
  62.  
  63. //
  64. // Exports
  65. //
  66.  
  67. extern "C" void ShowAboutBoxEntry( Environment* ev, ODWindowState* windowState );
  68.  
  69. //
  70. // Private
  71. //
  72.  
  73. static short GetMainDeviceDepth( ODBoolean *isColor )
  74. {
  75.     GDHandle        device;
  76.     short            depth;
  77.     PixMapHandle    pmap;
  78.     
  79.     depth  = 1;
  80.     *isColor = kODTrue;
  81.     device = GetMainDevice();
  82.     if (
  83.         (TestDeviceAttribute(device, screenDevice)) &&
  84.         (TestDeviceAttribute(device, screenActive))
  85.     ) {
  86.         pmap  = (*device)->gdPMap;
  87.         depth = (*pmap)->pixelSize;
  88.         *isColor = TestDeviceAttribute(device,gdDevType);
  89.     }
  90.     
  91.     return(depth);
  92. }
  93.  
  94. static DialogPtr OpenAboutBoxDialog( )
  95. {
  96.     DialogPtr aboutScreen = NULL;
  97.     Boolean color;
  98.     short depth = GetMainDeviceDepth(&color);
  99.     
  100.     short pictID = kODDlgAboutBoxDefaultPICTID;
  101.  
  102.     Str255 s255; s255[0]=0;
  103.     WindowPtr ww = FrontWindow();
  104.     if (ww)
  105.         GetWTitle(ww, s255);
  106.     else
  107.         BlockMove(LMGetCurApName(), s255, 32);
  108.         
  109.     if (!EqualString(s255, "\pAbout OpenDoc...", TRUE, FALSE))
  110.     {
  111.                     // Note, the above string is NEVER user visible, so there is no need
  112.                     // to worry about localizing it.
  113.         if( !color && depth>=4 )
  114.             pictID = kODDlgAboutBox16GrayPICTID;    // Use grayscale
  115.         else if( depth>=8 )
  116.             pictID = kODDlgAboutBoxBestPICTID;        // Use 8-bit color
  117.         else
  118.             pictID = kODDlgAboutBoxBWPICTID;        // Use black-and-white
  119.     }
  120.  
  121.     if( Get1Resource('DLOG',kODDlgAboutBoxDLOGID) )
  122.         aboutScreen = GetNewDialog(kODDlgAboutBoxDLOGID,NULL,(WindowPtr)-1L);
  123.     if( aboutScreen ) {
  124.         short        itemHit;
  125.         Handle        scratchHandle = kODNULL;
  126.         Rect        itemRect;
  127.     
  128.         GetDialogItem(aboutScreen, 1, &itemHit, &scratchHandle, &itemRect);
  129.         
  130.         PicHandle pictHandle = (PicHandle)Get1Resource('PICT', pictID);
  131.         
  132.         TEHandle te = ((DialogPeek)aboutScreen)->textH;
  133.         (**te).just = teJustCenter;
  134.  
  135.         // Get the CFM version and the vers resource
  136.         ODVersion    cfmVersion = 0;
  137.         OSErr err = ODGetOpenDocVersion( &cfmVersion );
  138.         VersRsrc **vers = (VersRsrc**) Get1Resource('vers',2);
  139.         
  140.         if ( err != noErr && vers == kODNULL )
  141.         {
  142.             // Worst case--can't get any version info
  143.             WARN( "Can’t find any version info!" );
  144.             ParamText( "\p", kODNULL, kODNULL, kODNULL );
  145.         }
  146.         else if ( vers == kODNULL || ((**vers).versionCode >> 16) != ( cfmVersion >> 16 )) 
  147.         {
  148.             // Couldn't get vers data, or it doesn't match the CFM version number
  149.             // (high word only), so use the CFM version
  150.             WARN( "CFM version does not match the vers resource!" );
  151.             
  152.             char versionBuf[100];
  153.             const unsigned long kNibbleMask = 0x0000000F;
  154.             ODUShort major =  (( cfmVersion >> 28 ) & kNibbleMask ) * 10
  155.                                 +(( cfmVersion >> 24 ) & kNibbleMask );
  156.             ODUShort minor =  (( cfmVersion >> 20 ) & kNibbleMask );
  157.             ODUShort update = (( cfmVersion >> 16 ) & kNibbleMask );
  158.             sprintf( versionBuf, update ? "%d.%d.%d" : "%d.%d",
  159.                         major, minor, update ? update : kODNULL );
  160.             StringPtr versionStr = CToPascalString( versionBuf );
  161.             ParamText( versionStr, kODNULL, kODNULL, kODNULL );
  162.         }
  163.         else
  164.         {
  165.             // Use the vers resource, since it contains pre-release version info
  166.             HLock((Handle)vers);
  167.             ParamText( (**vers).versionStr, kODNULL, kODNULL, kODNULL );
  168.         }
  169.         
  170.         if ( vers != kODNULL )
  171.         {
  172.             ReleaseResource( (Handle)vers );
  173.             vers = kODNULL;
  174.         }
  175.  
  176.         ShowWindow(aboutScreen);
  177.         SelectWindow(aboutScreen);
  178.         DrawDialog(aboutScreen);
  179.         SetPort(aboutScreen);
  180.         if (pictHandle)
  181.         {
  182.             HLock((Handle)pictHandle);
  183.             DrawPicture(pictHandle, &itemRect);
  184.             HUnlock((Handle)pictHandle);
  185.             ReleaseResource((Handle)pictHandle);
  186.         }
  187.  
  188.         ValidRect(&aboutScreen->portRect);
  189.     }
  190.     return aboutScreen;
  191. }
  192.  
  193. //
  194. // Public
  195. //
  196.  
  197. void ShowAboutBoxEntry( Environment* ev, ODWindowState* windowState )
  198. {
  199.     CUsingLibraryResources r;
  200.     ODSShort itemHit;
  201.     GrafPtr savePort;    ODVolatile(savePort);
  202.     GetPort(&savePort);
  203.     
  204.     windowState->DeactivateFrontWindows(ev);
  205.     TRY
  206.         DialogPtr aboutDlg = OpenAboutBoxDialog();
  207.     
  208.         ModalDialog(kODNULL /*modalFilter*/, &itemHit);
  209.         if (aboutDlg)
  210.             DisposeDialog(aboutDlg);
  211.     CATCH_ALL
  212.         windowState->ActivateFrontWindows(ev);
  213.         SetPort(savePort);
  214.         RERAISE;
  215.     ENDTRY
  216.     windowState->ActivateFrontWindows(ev);
  217.     SetPort(savePort);
  218. }
  219.